﻿using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SouthernLand.Common.BOL.Articles
{
    [ParseChildren(true)]
    public class ddlArticleCategory : DropDownList
    {
        public ddlArticleCategory()
        {
            Items.Insert(0, new ListItem(ResourceManager.GetString("PleaseSelect"), "1"));
            List<ArticleCategory> rootArticleCategory = ArticleCategory.GetArticleCategoryByParentID(1);
                // get root level ones

            if (rootArticleCategory.Count > 0)
            {
                foreach (ArticleCategory c in rootArticleCategory)
                {
                    string strTree = " ";
                    CssClass = "dropdownlistParent";
                    var l = new ListItem(strTree + ((Globals.LangVietNam()) ? c.CateName : c.CateName_en),
                                         c.CateID.ToString());
                    l.Attributes.Add("style", "font-weight:Bold;");
                    Items.Add(l);
                    populateArticleCategoryAdd(c.CateID);
                }
            }
            else
            {
                Items.Insert(0, new ListItem("ArticleCategory", "1"));
            }
        }

        private void populateArticleCategoryAdd(int ParentID)
        {
            string strTree = "     ";
            List<ArticleCategory> rootArticleCategory = ArticleCategory.GetArticleCategoryByParentID(ParentID);
                // get root level ones
            foreach (ArticleCategory c in rootArticleCategory)
            {
                var l = new ListItem(strTree + ((Globals.LangVietNam()) ? c.CateName : c.CateName_en),
                                     c.CateID.ToString());
                Items.Add(l);
                populateArticleCategoryAdd2(c.CateID);
            }
        }

        private void populateArticleCategoryAdd2(int ParentID)
        {
            string strTree = "        ";
            List<ArticleCategory> rootArticleCategory = ArticleCategory.GetArticleCategoryByParentID(ParentID);
                // get root level ones
            foreach (ArticleCategory c in rootArticleCategory)
            {
                var l = new ListItem(strTree + ((Globals.LangVietNam()) ? c.CateName : c.CateName_en),
                                     c.CateID.ToString());
                Items.Add(l);
                populateArticleCategoryAdd(c.CateID);
            }
        }
    }
}